#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dirent.h>
#include <unistd.h>

char img_path[500][1000];
int img_num = 0;
int readFileList(char *basePath)
{
    DIR *dir;
    struct dirent *ptr;
    if((dir = opendir(basePath)) == NULL)
    {
        perror("Open dir error...");
        exit(1);
    }
    while((ptr = readdir(dir)) != NULL)
    {
        if(strcmp(ptr->d_name,".") == 0 || strcmp(ptr->d_name, "..") == 0)
            continue;
        else if(ptr->d_type == 8)
        {
            strcpy(img_path[img_num], ptr->d_name);
            //printf("ptr->d_name = %s, img_path[img_num] = %s\n", ptr->d_name, img_path[img_num]);
            img_num++;
        }
        else
        {
            continue;
        }
    }
    /// 取到文件名后，直接添加到json中。
    closedir(dir);
    return 1;
}

int main()
{
    char basePath[100];
    /*
    printf("Enter Image Path: ");
    fflush(stdout);
    char basePath[100]="data/";
    char* input;
    input = fgets(input, 256, stdin);
    if(!input)
        return -1;
    strtok(input, "\n");
    strcat(basePath, input);
    strcat(basePath,"/");
    basePath="/home/yyj/Downloads/";
    */
    strcpy(basePath, "/home/yyj/Downloads/");
    readFileList(basePath);
    for(int i = 0; i < img_num; i++)
    {
        printf("%s\n", img_path[i]);
    }
    return 0;
}